package com.ruoyi.web.controller.competitionNEW;

import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.file.MimeTypeUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.competitionNEW.domain.Competition;
import com.ruoyi.competitionNEW.service.ICompetitionService;
import com.ruoyi.file_info.domain.CompetitionFileInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile;

/**
 * 赛事Controller
 * 
 * @author ruoyi
 * @date 2023-12-21
 */
@RestController
@RequestMapping("/system/competition")
public class CompetitionController extends BaseController {
    @Autowired
    private ICompetitionService competitionService;

    /**
     * 查询赛事列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Competition competition) {
        startPage();
        List<Competition> list = competitionService.selectCompetitionList(competition);
        return getDataTable(list);
    }

    /**
     * 导出赛事列表
     */
    @PreAuthorize("@ss.hasPermi('system:competition:export')")
    @Log(title = "赛事", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Competition competition) {
        List<Competition> list = competitionService.selectCompetitionList(competition);
        ExcelUtil<Competition> util = new ExcelUtil<Competition>(Competition.class);
        util.exportExcel(response, list, "赛事数据");
    }

    /**
     * 获取赛事详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:competition:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(competitionService.selectCompetitionById(id));
    }

    /**
     * 新增赛事
     */
    @PreAuthorize("@ss.hasPermi('system:competition:add')")
    @Log(title = "赛事", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Competition competition) {
        return toAjax(competitionService.insertCompetition(competition));
    }

    /**
     * 修改赛事
     */
    @PreAuthorize("@ss.hasPermi('system:competition:edit')")
    @Log(title = "赛事", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Competition competition) {
        return toAjax(competitionService.updateCompetition(competition));
    }

    /**
     * 删除赛事
     */
    @PreAuthorize("@ss.hasPermi('system:competition:remove')")
    @Log(title = "赛事", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(competitionService.deleteCompetitionByIds(ids));
    }


    /**
     * 试题管理
     */
    /**
     * 查询试题列表
     */
    @GetMapping("/examlist")
    public TableDataInfo examlist(CompetitionFileInfo competitionFileInfo) {
        startPage();
        List<CompetitionFileInfo> list = competitionService.selectCompetitionFileInfoList(competitionFileInfo);
        return getDataTable(list);
    }

    @Log(title = "试题上传", businessType = BusinessType.IMPORT)
    @PostMapping("/addExamQuestions")
    public AjaxResult addExamQuestions(@RequestBody Map map){
//        System.out.println(map);
        competitionService.addExamQuestions(map);
        return AjaxResult.success("上传成功!");
    }





}
